home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / kerberos / pc / krb_libd.lha / Lib / Des / MAKE_P.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-05  |  1.7 KB  |  57 lines

  1. /*
  2.  * $Source: /mit/kerberos/src/lib/des/RCS/make_p.c,v $
  3.  * $Author: jtkohl $
  4.  *
  5.  * Copyright 1985, 1988 by the Massachusetts Institute of Technology.
  6.  *
  7.  * For copying and distribution information, please
  8.  * see the file <mit-copyright.h>.
  9.  *
  10.  * This routine generates the P permutation code for the DES.
  11.  */
  12.  
  13. #include <mit_copy.h>
  14. #include <stdio.h>
  15. #include "des_intn.h"
  16. #include "tables.h"
  17.  
  18. void gen(stream)
  19.     FILE *stream;
  20. {
  21.     int i;
  22.     /* P permutes 32 bit input R1 into 32 bit output R2 */    
  23.  
  24.     /* clear the output */
  25.     fprintf(stream,"    L2 = 0;\n");
  26. #ifndef    BIG
  27.     fprintf(stream,"    R2 = 0;\n");
  28.     fprintf(stream,
  29.         "/* P operations */\n/* from right to right */\n");
  30.     /* first list mapping from left to left */
  31.     for (i = 0; i <=31; i++)
  32.     if (P[i] < 32)
  33.         fprintf(stream,
  34. #ifdef BITS16            
  35.             "    if (R1 & (1UL<<%d)) R2 |= 1UL<<%d;\n",P[i],i);
  36. #else
  37.             "    if (R1 & (1<<%d)) R2 |= 1<<%d;\n",P[i],i);
  38. #endif /* BITS16 */
  39. #else /* BIG */
  40.     /* flip p into p_temp */
  41.     fprintf(stream,"    P_temp = R1;\n");
  42.     fprintf(stream,"    P_temp_p = (unsigned char *) &P_temp;\n");
  43.  
  44. #ifdef    LSBFIRST
  45.     fprintf(stream,"    R2 = P_prime[0][*P_temp_p++];\n");
  46.     fprintf(stream,"    R2 |= P_prime[1][*P_temp_p++];\n");
  47.     fprintf(stream,"    R2 |= P_prime[2][*P_temp_p++];\n");
  48.     fprintf(stream,"    R2 |= P_prime[3][*P_temp_p];\n");
  49. #else /* MSBFIRST */
  50.     fprintf(stream,"    R2 = P_prime[3][*P_temp_p++];\n");
  51.     fprintf(stream,"    R2 |= P_prime[2][*P_temp_p++];\n");
  52.     fprintf(stream,"    R2 |= P_prime[1][*P_temp_p++];\n");
  53.     fprintf(stream,"    R2 |= P_prime[0][*P_temp_p];\n");
  54. #endif /* MSBFIRST */
  55. #endif /* BIG */
  56. }
  57.